package org.oop3.duotai2;

public class testShangSu {
	public static void main(String[] args){
		
		//上溯   就是先定义一个父类变量     把子类的对象地址 传给 父类变量            再把父类变量强制转化为子类类型的变量
		Fruit ff = new Apple();
		Apple a =(Apple)ff;
		a.eat();
		
		Fruit ff1 = new Banana();
		Banana b = (Banana)ff1;
		b.eat();
		
		
		//反面例子    
		/*Fruit ff2 = new Banana();
		Apple c = (Apple)ff2;
		c.eat();*/
		
		
		//下溯 造型  
		
		Fruit ff3 = new Apple();
		if(ff3 instanceof Apple){
			Apple aa = (Apple) ff3;
			aa.eat();
		}
		Fruit ff4 = new Banana();
		if(ff4 instanceof Banana){
			Banana bb = (Banana) ff4;
			bb.eat();
		}
		
	}
}
